package com.geeker.module.sys.menu.sevice;

import com.geeker.module.sys.menu.domain.SysMenu;
import com.geeker.module.sys.menu.mapper.SysMenuMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class SysMenuService extends ServiceImpl<SysMenuMapper, SysMenu> {

    public Set<String> selectMenuPermsByRoleId(Long roleId) {
        List<String> perms = mapper.selectMenuPermsByRoleId(roleId);
        Set<String> permsSet = new HashSet<>();
        for (String perm : perms) {
            if (StringUtils.isNotEmpty(perm)) {
                permsSet.addAll(Arrays.asList(perm.trim().split(",")));
            }
        }
        return permsSet;
    }

    public Collection<String> selectMenuPermsByUserId(Long userId) {
        List<String> perms = mapper.selectMenuPermsByUserId(userId);
        Set<String> permsSet = new HashSet<>();
        for (String perm : perms) {
            if (StringUtils.isNotEmpty(perm)) {
                permsSet.addAll(Arrays.asList(perm.trim().split(",")));
            }
        }
        return permsSet;
    }

    public List<SysMenu> menuList() {
        return this.list();
    }
}
